#ifndef _SESSION_MGR_REQUESTHANDLER_H
#define _SESSION_MGR_REQUESTHANDLER_H

#include <memory>
#include <string>

#include "types.h"

#include "ConfigGenerator.h"

#include "cbsocket/DefaultCallback.h"
#include "cbsocket/LineHandler.h"

namespace session_mgr
{
    class ClientManager;
    class ConfigManager;
    
    class RequestHandler : public cbsocket::LineHandler
    {
        MARK_NONCOPYABLE(RequestHandler);
    public:
        RequestHandler(ConfigManager *configManager);
        
        void setSocket(cbsocket::DefaultCallback *socket);
        
        virtual void pushLine(const std::string& line);
        
    private:
        void parseLine(std::string const& line);
        void requestFinish();
        void response(int code, std::string const& message);
        void responseFinish();
        
        int responseCode;
        std::string responseBuffer;
        
        ConfigGeneratorPtr config;
        
        cbsocket::DefaultCallback *socket;
        ConfigManager *configManager;
        
        std::auto_ptr<ClientManager> clientManager;
        
        bool finished, error;
    };
}

#endif
